package com.seari.custody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.junit.jupiter.api.Test;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class FileDemo1 {

    @Test
    public void min1() throws Exception{

        Map<String, String> map=new HashMap<>();
        map.put("no","202102002");
        map.put("fileId","168336");
        map.put("FileName","政类技审意见v1.0.docx");
        map.put("fileType","word");
        map.put("personNumber","01010006407");
        map.put("type","5");
        map.put("UUID","b0a1c9fa-fb5d-4463-b3e9-f938ab6c1371");
        Map<String, String> kein = KEIN(map);
        String code=kein.get("code");
        String message=kein.get("message");
        System.out.println(code);
        System.out.println(message);
    }



    public static Map<String, String> KEIN(Map<String,String> review) throws Exception{
        Map<String, String> map=new HashMap<>();
        String serverURL ="http://10.1.14.200/MMS/api/plotting/uploadTechnicalFile";
        StringBuffer sbf = new StringBuffer();
        String strRead = null;
        URL url = new URL(serverURL);
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        // 请求post方式
        connection.setRequestMethod("POST");
        connection.setDoInput(true);
        connection.setDoOutput(true);
        // header内的的参数在这里set    connection.setRequestProperty("健, "值");
        connection.setRequestProperty("Content-Type", "application/json");
//        connection.setRequestProperty("Info_Token", idcard.getInfoToken());
        connection.connect();
        OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(),"UTF-8");
        // body参数在这里put到JSONObject中
        String json = JSON.toJSONString(review);//map转String
        JSONObject parm = JSON.parseObject(json);//String转JSONObject
        writer.write(parm.toString());
        writer.flush();
        InputStream is = connection.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
        while ((strRead = reader.readLine()) != null) {
            sbf.append(strRead);
            sbf.append("\r\n");
        }
        reader.close();
        connection.disconnect();
        JSONObject jsonObject= JSON.parseObject(String.valueOf(sbf));
        String code=jsonObject.getString("code");
        String message=jsonObject.getString("message");
        System.out.println("code的值"+code);
        if("500".equals(code)){
            map.put("code","500");
            map.put("message",message);
            return map;
        }
        if("200".equals(code)){
            map.put("code","200");
            map.put("message",message);
            return map;
        }
        return map;
    }



}
